﻿Imports Negocio
Imports Utilitario
Public Class frmAprobacion

    Dim servicio As New PedidoNegocio

    Dim cia As String = "01"
    Dim suc As String = "01"
    Dim codPedido As String = ""
    Dim tipoDocumento As String = ""
    Dim estado As String = EST_Aprobado

    Sub New(pedido As String, tdoc As String)

        ' Llamada necesaria para el diseñador.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
        Me.codPedido = pedido
        Me.tipoDocumento = tdoc
    End Sub

    Sub cargarMotivos()
        Dim ds As DataSet = servicio.obtenerMotivosDesaprobacion()
        With cboMotivo
            .DataSource = ds.Tables(0)
            .ValueMember = "item"
            .DisplayMember = "descrip"
        End With
    End Sub

    Private Sub frmAprobacion_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtObservaciones.Focus()
        lblPedido.Text = "PEDIDO : " & codPedido
        cargarMotivos()
    End Sub

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub btnAceptar_Click(sender As System.Object, e As System.EventArgs) Handles btnAceptar.Click
        servicio.actualizarAprobacionPedido(cia, suc, tipoDocumento, codPedido, estado, txtObservaciones.Text.Trim, cboMotivo.SelectedValue.ToString)

        frmMenu.formDocumento.pedido.DCI_Estado = estado
        frmMenu.formDocumento.pedido.DCI_OBSCredito = txtObservaciones.Text.Trim

        DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub rbNo_CheckedChanged(sender As Object, e As System.EventArgs) Handles rbNo.CheckedChanged
        If rbNo.Checked = True Then
            estado = EST_Observado
            cboMotivo.Enabled = True
            cboMotivo.Focus()
        Else
            cboMotivo.Enabled = False
        End If
    End Sub

    Private Sub cboMotivo_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles cboMotivo.SelectedValueChanged
        If cboMotivo.SelectedValue.ToString <> "0" Then
            txtObservaciones.Focus()
        End If
    End Sub

    Private Sub rbSi_CheckedChanged(sender As Object, e As System.EventArgs) Handles rbSi.CheckedChanged
        estado = EST_Aprobado
        txtObservaciones.Focus()
    End Sub

End Class